package com.atguigu.gmall.search.rpc;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.Goods;
import com.atguigu.gmall.search.service.SearchService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/inner/rpc/search")
@RestController
public class SearchRpcController {
    @Autowired
    private SearchService searchService;

    /**
     * 商品上架
     * @param good
     * @return
     */
    @PostMapping("/up/goods")
    public Result up(@RequestBody Goods good){
     searchService.save(good);
     return Result.ok();
    }

    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping ("/down/{skuId}")
    public Result down(@PathVariable("skuId") Long skuId){
        searchService.down(skuId);
        return Result.ok();
    }
    @PostMapping("/searchGoods")
    public Result<SearchRespVo> search(@RequestBody SearchParamVo searchParamVo){
        //1检索
        SearchRespVo respVo = searchService.search(searchParamVo);
        return Result.ok(respVo);
    }
}
